﻿using Microsoft.AspNetCore.SignalR;
using System.Diagnostics;

namespace XmppWebTest
{
    public class ChatHub : Microsoft.AspNetCore.SignalR.Hub
    {
        private readonly XmppService _xmppService;  // 注入 XmppService

        public ChatHub(XmppService xmppService)
        {
            _xmppService = xmppService;
        }

        // 处理前端发送的消息 -> 发送到 XMPP
        public async Task SendMessage(string user, string message)
        {
            Debug.WriteLine($"前端发送消息：{user}: {message}");

            // 发送消息到所有 SignalR 客户端
            await Clients.All.SendAsync("ReceiveMessage", user, message);

            // 发送消息到 XMPP 服务器
            await _xmppService.SendMessageToXmpp("zzh@izeellvnf5htoqz", message);
        }

        //// 前端发送消息 -> 发送到 XMPP
        //public async Task SendMessage(string user, string message)
        //{
        //    Debug.WriteLine($"前端发送消息：{user}: {message}");

        //    // 发送消息到所有 SignalR 客户端
        //    await Clients.All.SendAsync("ReceiveMessage", user, message);

        //    // 发送消息到 XMPP 服务器
        //    await _xmppClient.SendChatMessageAsync("zzh@izeellvnf5htoqz", message);
        //}
    }
}
